# -*- coding: utf-8 -*-
"""
月度比赛赛程模型
"""
from app import db
from datetime import datetime

class MonthlyCompetitionMatch(db.Model):
    __tablename__ = 'monthly_competition_matches'
    id = db.Column(db.BigInteger, primary_key=True)
    competition_id = db.Column(db.BigInteger, db.ForeignKey('monthly_competitions.id'), nullable=False)
    group = db.Column(db.Enum('A', 'B', 'C'), nullable=False)
    subgroup = db.Column(db.Integer, nullable=True, comment='小组编号')
    round = db.Column(db.Integer, nullable=False, comment='轮次')
    player_a_id = db.Column(db.BigInteger, db.ForeignKey('users.id'), nullable=False)
    player_b_id = db.Column(db.BigInteger, db.ForeignKey('users.id'), nullable=False)
    table_id = db.Column(db.Integer, db.ForeignKey('tables.id'), nullable=True)
    match_time = db.Column(db.DateTime, nullable=True)
    result = db.Column(db.String(32), nullable=True, comment='比赛结果')
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

    player_a = db.relationship('User', foreign_keys=[player_a_id])
    player_b = db.relationship('User', foreign_keys=[player_b_id])
    table = db.relationship('Table')
    competition = db.relationship('MonthlyCompetition')
